package database;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import objectView.SCCompany;
import utility.StringUtil;
import clientMain.Login;
import clientMain.Main;

public class SCDelegate {
	
	public Vector<SCCompany> getListSC(int page, String sort, boolean flag){
		Vector<SCCompany> list = new Vector<SCCompany>();
		try {
			Login.conn.setAutoCommit(false);
			CallableStatement cst = Login.conn.prepareCall("{call sp_ListSC(?,?,?,?,?)}");
			cst.setInt(1, Main.comId);
			cst.setInt(2, Main.record);
			cst.setInt(3, page);
			cst.setString(4, sort);
			cst.setBoolean(5, flag);
			ResultSet rs = cst.executeQuery();
			while(rs.next()){
				SCCompany sc = new SCCompany();
				sc.setsCId(rs.getInt("SC_Id"));
				sc.setsCName(StringUtil.getFilterIllegal(rs.getString("SC_Name")), rs.getInt("SC_AM_PM"));
				sc.setsCMoney(Integer.toString(rs.getInt("SC_Money")));
				sc.setDepName(StringUtil.getFilterIllegal(rs.getString("Dep_Name")));
				sc.setPosName(StringUtil.getFilterIllegal(rs.getString("Pos_Name")));
				sc.setEmTName(StringUtil.getFilterIllegal(rs.getString("EmT_Name")));
				list.add(sc);
			}
			Login.conn.commit();
		} catch (SQLException e) {
			list = null;
			e.printStackTrace();
		}
		return list;
	}
}
